package com.example.practice.service.impl;

import com.example.practice.dao.ActivityDao;
import com.example.practice.entity.Activity;
import com.example.practice.entity.Rule;
import com.example.practice.entity.User;
import com.example.practice.service.ActivityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Activity)表服务实现类
 *
 * @author makejava
 * @since 2023-12-21 10:00:20
 */
@Service("activityService")
public class ActivityServiceImpl implements ActivityService {
    @Resource
    private ActivityDao activityDao;

    @Override
    public List<Activity> getJoinActivity(Integer uid) {
        return this.activityDao.getJoinActivity(uid);
    }

    @Override
    public List<Activity> getNotJoinActivity(Integer uid) {
        return this.activityDao.getNotJoinActivity(uid);
    }

    @Override
    public List<Activity> getReleaseActivity(Integer uid) {
        return this.activityDao.getReleaseActivity(uid);
    }
    @Override
    public Integer queryCheckStatus(Integer uid,Integer aid){
        return this.activityDao.queryCheckStatus(uid,aid);
    }
    @Override
    public Integer createActivity(Integer uid, Activity activity) {
        int i=this.activityDao.createActivity(uid, activity);
        if (i == 1) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public Integer updateActivity(Activity activity) {
        if (this.activityDao.updateActivity(activity) == 1) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public Integer studentJoin(Integer uid, Integer aid) {
        this.activityDao.studentJoin(uid, aid);
        return 1;
    }

    @Override
    public String activityRelease(Rule rule, Integer sid) {
        if (rule.getPeople() == 0) {
            //都发布
            this.activityDao.activityRelease(rule, sid);
            return "both";
        } else if (rule.getPeople() == 1) {
            //老师
            this.activityDao.activityRelease1(rule, sid);
            return "teacher";
        } else if (rule.getPeople() == 2) {
            //学生发布
            this.activityDao.activityRelease2(rule, sid);
            return "student";
        } else {
            return "fail";
        }
    }

    @Override
    public Boolean queryIfJoin(Integer uid, Integer aid) {
        Integer i = this.activityDao.queryIfJoin(uid, aid);
        if (i == 0) {
            //没参加
            return false;
        } else {
            return true;
        }
    }
    @Override
    public Boolean queryIfRelease(Integer aid){
         if (this.activityDao.queryIfRelease(aid)==1){
            return true;
         }
         else {
             return false;
         }
    }
    @Override
    public Integer ExitActivity(Integer uid, Integer aid) {
        return this.activityDao.ExitActivity(uid, aid);
    }

    @Override
    public Activity getDetail(Integer aid){
        return this.activityDao.getDetail(aid);
    }

    @Override
    public String updateActivityStatus(Integer aid){
        //0是未发布
        if(this.activityDao.updateActivityStatus(aid)==1){
            return "成功";
        }
        else {
            return "失败";
        }
    }

    @Override
    public String updateActivityStatus1(Integer aid){
        //1是发布
        if(this.activityDao.updateActivityStatus1(aid)==1){
            return "成功";
        }
        else {
            return "失败";
        }
    }

    @Override
    public Integer deleteActivity(Integer aid){
        return this.activityDao.deleteActivity(aid);
    }

    @Override
    public Integer addNum(Integer aid) {
        return this.activityDao.addNum(aid);
    }
    @Override
    public Integer subNum(Integer aid) {
        return this.activityDao.subNum(aid);
    }

    @Override
    public Activity queryByaid(Integer aid, Integer uid) {return this.activityDao.queryByaid(aid, uid);}

    @Override
    public Activity queryByName(String name, Integer uid) {return this.activityDao.queryByName(name, uid);}

    @Override
    public List<Activity> getAllByUid(Integer uid) {
        return this.activityDao.getAllByUid(uid);
    }

    @Override
    public Activity getAct(Integer fid) {
        return this.activityDao.getAct(fid);
    }

    @Override
    public List<Activity> getAllAct() {
        return this.activityDao.getAllAct();
    }
    public Activity queryIdByName(String name) {return this.activityDao.queryIdByName(name);}

    @Override
    public String updateActivityStatus2(Integer aid){
        //0是未发布
        if(this.activityDao.updateActivityStatus2(aid)==1){
            return "成功";
        }
        else {
            return "失败";
        }
    }
    @Override
    public Activity getActivityById(Integer id){
        return this.activityDao.getActivityById(id);
    }

    @Override
    public List<Activity> getActivityByUid(Integer uid){return this.activityDao.getActivityByUid(uid);}

    @Override
    public List<Activity> getDistName() {
        return this.activityDao.getDistName();
    }

    @Override
    public String getByAid(Integer aid) {return this.activityDao.getByAid(aid);}
    public Integer insertActivityAndSchool(Integer uid,List<String> sName,Integer aid){
        return this.activityDao.insertActivityAndSchool(uid,sName,aid);
    }

    @Override
    public Rule getActRuleByAid(Integer aid) {
        return this.activityDao.getActRuleByAid(aid);
    }

    @Override
    public List<User> getUserNum(Integer aid) {
        return this.activityDao.getUserNum(aid);
    }

    @Override
    public List<Activity> getAllActivity() {
        return this.activityDao.getAllActivity();
    }
}
